<template>
  <nav class="site-navbar" :class="'site-navbar--' + navbarLayoutType">
    <div class="site-navbar__header">
      <h1 class="site-navbar__brand" @click="$router.push({ name: 'home' })">
        <a class="site-navbar__brand-lg" href="javascript:;">fastgrow平台</a>
        <a class="site-navbar__brand-mini" href="javascript:;">网络用户端</a>
      </h1>
    </div>
    <div class="site-navbar__body clearfix">
      <el-menu
        class="site-navbar__menu site-navbar__menu--right"
        mode="horizontal">
        <el-menu-item index="1" @click="$router.push({ name: 'image' })">
            <el-badge class="item">图像列表</el-badge>
          </el-menu-item>
        <el-menu-item index="2" @click="$router.push({ name: 'community' })">
          <el-badge value="hot">交流中心</el-badge>
        </el-menu-item>
        <el-menu-item index="3" @click="$router.push({ name: 'message' })">
          <el-badge :value="this.$store.state.user.message" class="item">我的消息</el-badge>
        </el-menu-item>
        <el-menu-item class="site-navbar__avatar" index="3">
          <el-dropdown :show-timeout="0" placement="bottom">
            <span class="el-dropdown-link">
              <img :src="avatar" style="width: 40px;height: 40px;" :alt="userName">
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
              <el-dropdown-item @click.native="updateInfoHandle()">个人信息</el-dropdown-item>
              <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-menu-item>
      </el-menu>
    </div>
    <!-- 弹窗, 修改密码 -->
    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
    <!-- 弹窗, 个人信息 -->
    <update-info v-if="updatePassowrdVisible" ref="updateInfo"></update-info>
  </nav>
</template>

<script>
  	/* eslint-disable */
  import UpdatePassword from './main-navbar-update-password'
  import UpdateInfo from './common/main-navbar-info.vue'
  import { clearLoginInfo } from '@/utils'
  export default {
    data () {
      return {
        updatePassowrdVisible: false,
      }
    },
    components: {
      UpdatePassword,
      UpdateInfo
    },
    computed: {
      navbarLayoutType: {
        get () { return this.$store.state.common.navbarLayoutType }
      },
      sidebarFold: {
        get () { return this.$store.state.common.sidebarFold },
        set (val) { this.$store.commit('common/updateSidebarFold', val) }
      },
      mainTabs: {
        get () { return this.$store.state.common.mainTabs },
        set (val) { this.$store.commit('common/updateMainTabs', val) }
      },
      userName: {
        get () { return this.$store.state.user.name }
      },
      avatar: {
        get () { return this.$store.state.user.avatar },
        set (val) { this.$store.commit('user/updateAvatar', val) }
      }
    },
    activated() {
      console.log('查找')
    },
    methods: {
      // 修改密码
      updatePasswordHandle () {
        this.updatePassowrdVisible = true
        this.$nextTick(() => {
          this.$refs.updatePassowrd.init()
        })
      },
      // 个人信息
      updateInfoHandle () {
        this.updatePassowrdVisible = true
        this.$nextTick(() => {
          this.$refs.updateInfo.init()
        })
      },
      // 退出
      logoutHandle () {
        this.$confirm(`确定进行[退出]操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/login/logout'),
            method: 'post',
            data: this.$http.adornData()
          }).then(({data}) => {
            if (data.success) {
              clearLoginInfo()
              this.$router.push({ name: 'login' })
            }
          })
        }).catch(() => {})
      }
    }
  }
  // #99eaff
</script>
<style scoped>
.el-menu.el-menu--horizontal {
    border-bottom: solid 1px #e6e6e6;
}
.el-menu--horizontal {
    border-right: none;
}
.site-navbar__brand-lg {
    height: 61px !important;
    line-height: 61px !important;
}
.el-menu.el-menu--horizontal {
    background: #273471 !important;
}
.el-menu--horizontal>.el-menu-item {
    color: #FFFFFF !important;
}
.el-menu--horizontal>.el-menu-item:not(.is-disabled):focus, .el-menu--horizontal>.el-menu-item:not(.is-disabled):hover, .el-menu--horizontal>.el-submenu .el-submenu__title:hover {
    background-color: #409EFF !important;
}
.site-navbar__body {
    position: relative;
    margin-left: 230px;
    padding-right: 15px;
    background-color: #273471 !important;
}
  .site-navbar {
      height: 61px !important;
      /* background-color: #273471; */
  }
</style>
